# 创建一个公共断言
import json
import app

def comment_assert(testcase, response, expect_status_code, expect_success, expect_code, expect_message):
    # 从response对象中，解析出JSON格式响应数据
    res_json = response.json()
    # 断言状态码等于200
    testcase.assertEqual(expect_status_code, response.status_code)
    # 断言success
    testcase.assertEqual(expect_success, res_json.get("success"))
    # 断言code
    testcase.assertEqual(expect_code, res_json.get("code"))
    # 断言message
    testcase.assertIn(expect_message, res_json.get("message"))


# 读取外部文件中的测试数据
def read_file(file_name):
    # 读取文件的路径
    file_path = app.PROJECT_PATH + "\\data\\{}.json".format(file_name)
    # 获取外部文件中的测试数据
    with open(file_path, encoding="utf-8")as f:
        # 将读取到的测试数据解析为JSON
        json_data = json.load(f)
        # 将测试数据写入到列表嵌套元组的变变量中
    data_list = list()
    #    把列表中的字典进行遍历从中获取字典中的值,放入到元组中
    for case_data in json_data:
        case_data_tuple = tuple(case_data.values())
        # 返回到嵌套元组的变量
        data_list.append(case_data_tuple)
    print("最终结果展示", data_list)
    return data_list


if __name__ == '__main__':
    read_file("login_case_data")
